
package ma.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.beans.EventHandler;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.WindowConstants;
import java.awt.event.FocusListener;
import javax.swing.JTextField;

public class GuiView {

    public static JFrame create(GuiController guiController) {
        JFrame frame = new JFrame();

        JPanel contentPane = (JPanel) frame.getContentPane();

        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{18, 0, 6, 35, 0, 20, 12};
        gridBagLayout.rowHeights = new int[]{20, 0, 6, 0, 18, 0, 12};
        gridBagLayout.columnWeights = new double[]{0, 0, 0, 0, 0, 1, 0};
        gridBagLayout.rowWeights = new double[]{1, 0, 0, 0, 0, 0, 0};
        contentPane.setLayout(gridBagLayout);

        JTextField textField = new JTextField();
        textField.setEditable(false);
        textField.setEnabled(false);
        textField.addFocusListener(EventHandler.create(FocusListener.class, guiController, "setLabel", "source.text", "focusLost"));
        contentPane.add(textField, new GridBagConstraints(3, 3, 3, 1, 0.0, 0.0, 256, 2, new Insets(0, 0, 0, 0), 0, 0));

        JLabel label = new JLabel();
        label.setLabelFor(textField);
        label.setText("Datei :");
        contentPane.add(label, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
        contentPane.add(new JProgressBar(), new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, 17, 0, new Insets(0, 0, 0, 0), 0, 0));

        JButton button = new JButton();
        button.setText("Start indexing...");
        button.addActionListener(EventHandler.create(ActionListener.class, guiController, "startIndexing"));
        contentPane.add(button, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, 17, 0, new Insets(0, 0, 0, 0), 0, 0));
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setTitle("MediaArchive");
        frame.setBounds(new Rectangle(500, 22, 344, 155));

        return frame;
    }
}